package cn.itcast.pattern.proxy.jdk_proxy2;

import cn.itcast.pattern.proxy.jdk_proxy.SellTickets;
import cn.itcast.pattern.proxy.jdk_proxy.TrainStation;
import cn.itcast.pattern.proxy.jdk_proxy3.Operator;
import cn.itcast.pattern.proxy.jdk_proxy3.OperatorImpl;
import cn.itcast.pattern.proxy.jdk_proxy3.ProxyInvocationH;

import java.nio.channels.SeekableByteChannel;

public class Test {
    public static void main(String[] args) {

        //真实角色
        UserServiceImpl userService = new UserServiceImpl();
        //代理角色，不存在的
        ProxyInvocationHandler pih = new ProxyInvocationHandler();
        pih.setTarget(userService);//设置要代理的对象；
        //动态生成代理类
        UserService proxy = (UserService) pih.getProxy();
        proxy.select();


        //真是角色
        TrainStation trainStation = new TrainStation();
        //代理角色，不存在的
        ProxyInvocationHandler pih2 = new ProxyInvocationHandler();
        pih2.setTarget(trainStation);
        SellTickets proxy2 = (SellTickets) pih2.getProxy();
        proxy2.sell();




        Operator operator = new OperatorImpl();
        ProxyInvocationH pro  = new ProxyInvocationH();
        pro.setTarget(operator);
        Operator prox2 = (Operator) pro.getInstance();
        prox2.sub(1,3);

    }

}
